import  {
  ADD_COUNTER,
  ADD_TO_CART
} from './constant'

export default {
  addCart(context, payload) {
    return new Promise((resovle,reject) => {
      let oldProduct = context.state.cartList.find(function (item) {
        return item.iid == payload.iid
      })
  
      if(oldProduct){
        context.commit(ADD_COUNTER,oldProduct)
        resovle('数量加+1')
      } else {
        payload.count = 1
        context.commit(ADD_TO_CART,payload)
        resovle('加新的商品')
      }
    })
 
  }
}